package com.hncj.result;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;


@Data
public class R<T> {

    private String code; //编码 参考result.CODE

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> R<T> success(T object) {//成功
        R<T> r = new R<T>();
        r.data = object;
        r.code = CODE.SUCCESS;
        return r;
    }

    public static <T> R<T> error(String msg) {//错误
        R r = new R();
        r.msg = msg;
        r.code = CODE.ERROR;
        return r;
    }

    public static <T> R<T> other(String msg,String CODE) {//其他情况
        R r = new R();
        r.msg = msg;
        r.code = CODE;
        return r;
    }

    public R<T> add(String key, Object value) {//追加数据
        this.map.put(key, value);
        return this;
    }

}
